package com.fysports.web.kit.upload;

import com.google.common.collect.Maps;
import com.fysports.web.kit.umeditor.Uploader;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Class title: UME用helper     <br/>
 * Describe:                    <br/>
 * Created by konbluesky           <br/>
 * Date : 15/12/10 下午8:01       <br/>
 * Project : jdmdataServer    <br/>
 */
public class UmeUploadHelper extends UploadHelper {
    private HttpServletRequest request;
    private Uploader uploader;

    /**
     * TODO 为完成
     */
    public UmeUploadHelper(HttpServletRequest req) {
        this.request=req;
        uploader=new Uploader(req);
        /*
        * 此处设置的路径，用LoadImageHandler 路由 以参数的方式转到loadimg()方法中。
        * */
        uploader.setSavePath("upload");
        String[] fileType = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" };
        uploader.setAllowFiles(fileType);
        uploader.setMaxSize(10000); //单位KB
    }

    /**
     * TODO 为完成
     */
    @Override
    public void upload() {
        try {
            uploader.upload();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * TODO 为完成
     */
    @Override
    public Object getResult() {
        Map<String, Object> vals = Maps.newHashMap();
        vals.put("name", uploader.getFileName());
        vals.put("originalName", uploader.getOriginalName());
        vals.put("size", uploader.getSize());
        vals.put("state", uploader.getState());
        vals.put("type", uploader.getType());
        vals.put("url", uploader.getUrl());
        return vals;
    }
}
